package com.gcb.controller;

import com.gcb.constant.MessageConstant;
import com.gcb.entity.PageResult;
import com.gcb.entity.QueryPageBean;
import com.gcb.entity.Result;
import com.gcb.pojo.CheckGroup;
import com.gcb.pojo.CheckItem;
import com.gcb.service.CheckGroupService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Author 35235
 * @Date 2021/8/4 21:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @DubboReference
    CheckGroupService checkGroupService;

    @RequestMapping("/findAll.do")
    public Result findAllFromCheckItem() {

        List<CheckItem> checkItemList = checkGroupService.findAllFromCheckItem();
        if (checkItemList.isEmpty()) {
            System.out.println("empty");
            return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
        } else {

            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, checkItemList);
        }
    }

    @RequestMapping("/findCheckItemIdsByCheckGroupId.do")
    public Result findCheckItemIdsByCheckGroupId(Integer id) {

        return checkGroupService.findCheckItemIdsByCheckGroupId(id);
    }

    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        System.out.println("--------已进入查询page页面");
        PageResult pageResult = checkGroupService.queryQuery(queryPageBean);
        return pageResult;

    }

    @RequestMapping("/add.do")
    public Result add(@RequestBody CheckGroup checkGroup, Integer[] checkitemIds) {
        System.out.println("checkitemIds = " + Arrays.toString(checkitemIds));
        return checkGroupService.add(checkitemIds, checkGroup);
    }

    @RequestMapping("/delete.do")
    public Result delete(Integer id) {
        return checkGroupService.delete(id);
    }

    @RequestMapping("/findById.do")
    public Result findById(Integer id) {
        return checkGroupService.findById(id);
    }

    @RequestMapping("/edit.do")
    public Result update(Integer[] checkitemIds, @RequestBody CheckGroup checkGroup) {

        return checkGroupService.update(checkitemIds, checkGroup);

    }
}
